module.exports = app => {
  const { STRING } = app.Sequelize;

  const Role = app.model.define('role', {
    name: {
      type: STRING,
    },
    //fixme???   unique: 'key_name' 唯一索引
    keyName: {
      type: STRING, unique: 'key_name'
    },
    desc: {
      type: STRING
    }
  },
      //todo indexes添加唯一性索引
      // {
      //   indexes: [
      //     { unique: true, fields: ['name'] },
      //     { unique: true, fields: ['key_name'] }
      //   ]
      // }
  );

  Role.associate = function() {
    //todo Many-To-Many associations  角色和权限表多对多  中间表role_right
    app.model.Role.belongsToMany(app.model.Right, { through: 'role_right' });
    //todo Many-To-Many associations  角色和用户表多对多  中间表user_role
    app.model.Role.belongsToMany(app.model.User, { through: 'user_role' });

  };

  return Role;
};
